$('[name = "join"]').click(function() {
		conn.send('{"type": "connectWith", "id": "' + 2 + '"}');
		$("#waitMessage").html("Моля изчакайте другият играч да приеме играта");
		$("#notice").show(1000);
});
$("#accept").click(function() {
	console.log("accept");
	$("#confirmGame").hide(1000);
	conn.send('{"type": "startGame"}');
	
});
$("#decline").click(function() {
	$("#confirmGame").hide(1000);
});
$('#ans1').click(function() {
	conn.send('{"type": "checkAnswer", "answer": "' + $('#ans1').attr("name") +'"}');
	$("#boxQ1").hide(1000);
});
$('#ans2').click(function() {
	conn.send('{"type": "checkAnswer", "answer": "' + $('#ans2').attr("name") +'"}');
	$("#boxQ1").hide(1000);
});
$('#ans3').click(function() {
	conn.send('{"type": "checkAnswer", "answer": "' + $('#ans3').attr("name") +'"}');
	$("#boxQ1").hide(1000);
});
$('#ans4').click(function() {
	conn.send('{"type": "checkAnswer", "answer": "' + $('#ans4').attr("name") +'"}');
	$("#boxQ1").hide(1000);
});
function showQuestion(question) {
	//	console.log("i vav funkciqta");

	if (question.answer != "") {		
		$("#textQuestion1").html(question.text);
		var answers = question.answer;
		for (var i = 0; i < 4; i++) {
			$("#ans" + (i+1)).html(answers[i].answer_text);
			$("#ans" + (i+1)).attr("name", answers[i].answer_id);
		}
		$("#boxQ1").show(1000);
	} else {
		
		$("#textQuestion2").html(question.text);
		$("#boxQ2").show(1000);
	}
}

$("#submitmsg").click(function() {
	$.post("index.php?page=home", {
		action : "getUserName"
	}, function (data, status) {
		
		var input = document.getElementById("usermsg");

		var message = '{"type": "broadcast", "usermsg":"' + input.value + '", "username": "' + data +'"}';
	    conn.send(message);
	    input.value = "";
	    input.focus();
	});
    
  });